<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据库错误 - 交易监控系统</title>
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
                'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
                sans-serif;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
            margin: 0;
            padding: 0;
            background-color: #f5f5f5;
        }

        .error-container {
            text-align: center;
            padding: 40px 20px;
            max-width: 800px;
            margin: 0 auto;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin-top: 50px;
        }
        
        .error-icon {
            font-size: 64px;
            color: #e74c3c;
            margin-bottom: 20px;
        }
        
        .error-title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #333;
        }
        
        .error-message {
            font-size: 16px;
            color: #555;
            margin-bottom: 30px;
            line-height: 1.5;
        }
        
        .error-actions {
            margin-top: 30px;
        }
        
        .btn {
            display: inline-block;
            padding: 10px 20px;
            margin: 0 10px;
            border-radius: 4px;
            text-decoration: none;
            font-weight: bold;
            transition: background-color 0.3s;
        }
        
        .btn-primary {
            background-color: #3498db;
            color: white;
        }
        
        .btn-warning {
            background-color: #f39c12;
            color: white;
        }
        
        .btn:hover {
            opacity: 0.9;
        }
        
        .error-details {
            margin-top: 40px;
            text-align: left;
            background-color: #f8f9fa;
            padding: 15px;
            border-radius: 4px;
            border-left: 4px solid #e74c3c;
        }
        
        .error-details pre {
            margin: 0;
            white-space: pre-wrap;
            font-family: monospace;
            font-size: 14px;
            color: #555;
        }
        
        .error-details-toggle {
            color: #3498db;
            cursor: pointer;
            margin-top: 20px;
            display: inline-block;
        }
    </style>
</head>
<body>
    <div class="error-container">
        <div class="error-icon">
            <i class="fas fa-database"></i>
        </div>
        
        <h1 class="error-title">数据库连接错误</h1>
        
        <div class="error-message">
            <p>系统无法连接到数据库。这可能是由于配置错误、数据库服务未启动或网络问题引起的。</p>
            <p>请检查您的数据库配置或尝试切换到SQLite数据库。</p>
        </div>
        
        <div class="error-actions">
            <a href="/database_config" class="btn btn-primary">
                <i class="fas fa-cog"></i> 修改数据库配置
            </a>
            
            <a href="/switch_to_sqlite" class="btn btn-warning">
                <i class="fas fa-database"></i> 切换到SQLite数据库
            </a>
            
            <a href="/db_config_editor" class="btn btn-primary">
                <i class="fas fa-edit"></i> 编辑配置文件
            </a>
            
            <a href="/" class="btn btn-primary">
                <i class="fas fa-home"></i> 返回首页
            </a>
        </div>
        
        <div class="error-details-toggle" onclick="toggleErrorDetails()">
            <i class="fas fa-chevron-down"></i> 显示详细错误信息
        </div>
        
        <div class="error-details" id="errorDetails" style="display: none;">
            <pre>错误详情将在此处显示
- 检查数据库服务器是否正在运行
- 验证连接参数（主机名、端口、用户名、密码）是否正确
- 确认数据库名称拼写正确
- 检查网络连接和防火墙设置
- 确保所需的数据库驱动已安装</pre>
        </div>
    </div>

    <script>
        function toggleErrorDetails() {
            const details = document.getElementById('errorDetails');
            const toggle = document.querySelector('.error-details-toggle');
            
            if (details.style.display === 'none') {
                details.style.display = 'block';
                toggle.innerHTML = '<i class="fas fa-chevron-up"></i> 隐藏详细错误信息';
            } else {
                details.style.display = 'none';
                toggle.innerHTML = '<i class="fas fa-chevron-down"></i> 显示详细错误信息';
            }
        }
        
        // 尝试获取URL中的错误参数并显示
        window.onload = function() {
            const urlParams = new URLSearchParams(window.location.search);
            const errorMsg = urlParams.get('error');
            if (errorMsg) {
                document.getElementById('errorDetails').textContent = decodeURIComponent(errorMsg);
            }
        };
    </script>
</body>
</html>